#include "TextureLibrary.h"

#include <iostream>
#include <SFML\Graphics\Image.hpp>

//TextureLibrary TextureLibrary::Default;

GLuint TextureLibrary::GetTexture(Texture_Enum Enum)
{
	return TexLib[Enum];
}

TextureLibrary::TextureLibrary() //:
	//IsInitialized(false)
{
	TexLib[Texture_Font1] = LoadTexture("Textures/Font1.png");
	TexLib[Texture_Font2] = LoadTexture("Textures/Font2.png");
	TexLib[Texture_Background] = LoadTexture("Textures/Background.png");
}

/*
void TextureLibrary::Initialize()
{
	if (IsInitialized)
	{
		std::cout << "Texture Library Re-Initialized\n";
		return;
	}
	else
	{
		TexLib[Texture_Font1] =			LoadTexture("Textures/Font1.png");
		TexLib[Texture_Font2] =			LoadTexture("Textures/Font2.png");
		TexLib[Texture_Background] =	LoadTexture("Textures/Background.png");
	}
}*/

TextureLibrary::~TextureLibrary()
{
//	if (IsInitialized)
		glDeleteTextures( Texture_Count, TexLib );//anderswo hin
}

GLuint TextureLibrary::LoadTexture(std::string FileName)
{
	GLuint ReturnTexture;

	sf::Image Img;
	sf::Vector2u ImgSize;

	if (!Img.loadFromFile(FileName))
		std::cout << "Error loading: " << FileName << "\n";

	ImgSize = Img.getSize();

	glGenTextures(1, &ReturnTexture);
	glBindTexture(GL_TEXTURE_2D, ReturnTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ImgSize.x, ImgSize.y, 0, GL_RGBA, GL_UNSIGNED_BYTE, Img.getPixelsPtr());
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
	return ReturnTexture;
}